﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Collections.Generic;

public partial class BaseData_SelectServiceStation : System.Web.UI.Page,ICallbackEventHandler
{
    string result = "";

    public event RepeaterCommandEventHandler ItemCommand;

    //protected void Page_PreInit(object sender, EventArgs e)
    //{
    //    Page.Theme = BLL.Common.GetWSMThemes();
    //}
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDropProvince();
        }
    }
    protected void BindDropProvince()
    {
        List<Model.Province> provinces = new BLL.Province().GetAllList();
        Province.DataSource = provinces;
        Province.DataTextField = "ProName";
        Province.DataValueField = "ProId";
        Province.DataBind();
        ListItem item = new ListItem();
        item.Value = "-1";
        item.Text = "";
        Province.Items.Insert(0, item);
    }

    protected void rptVIP_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (ItemCommand != null)
            ItemCommand(source, e);
    }

    public void RaiseCallbackEvent(string eventArgument)
    {
        try
        {
            string[] arrStr = eventArgument.Split('$');


            StringBuilder strSql = new StringBuilder();

            strSql.Append(" and SS_IsDel=0 ");
            strSql.Append(arrStr[0] == "" ? "" : " and SS_ID like '%" + arrStr[0] + "%' ");
            strSql.Append(arrStr[1] == "" ? "" : " and SS_name like '%" + arrStr[1] + "%' ");
            strSql.Append(arrStr[2] == "" ? "" : " and SS_Address like '%" + arrStr[2] + "%' ");
            if (arrStr[3] == "" || arrStr[3] == "-1")
            {
                strSql.Append("");
            }
            else
            {
                strSql.Append(" and SS_ProId='" + arrStr[3] + "' ");
            }

            if (arrStr[4] != "" && arrStr[4] != "000001")
            {
                strSql.Append(" and SS_CityId='" + arrStr[4] + "' ");
            }

            if (arrStr[5] != "" && arrStr[5] != "000001")
            {
                strSql.Append(" and SS_AreaId='" + arrStr[5] + "' ");
            }

            hidReceiveAddressInfo.Value = arrStr[3] + "$" + arrStr[4] + "$" + arrStr[5];
            int recordCount;
            DataSet dst = new BLL.ServiceSites().GetMain(1, 10000, strSql.ToString(), out recordCount);
            strSql = new StringBuilder();
            strSql.Append("<table class='tb' border='0' cellspacing='1' cellpadding='0'><tr class='z1'><td class='zt3'></td><td class='zt3'>编号</td><td class='zt3' style='width: 100px;'>");
            strSql.Append("名称</td><td class='zt3' style='width: 100px;'>联系电话1</td><td class='zt3' style='width: 100px;'>联系电话2</td><td class='zt3'>详细地址</td></tr>");
            for (int i = 0; i < dst.Tables[0].Rows.Count; i++)
            {
                strSql.Append("<tr class='z2'><td class='zt4'><input name='radio' type='radio' value='" + dst.Tables[0].Rows[i]["SS_ID"].ToString() + "|" + dst.Tables[0].Rows[i]["SS_Name"].ToString() + "' /></td>");
                strSql.Append("<td class='zt4'>" + dst.Tables[0].Rows[i]["SS_ID"].ToString() + "</td>");
                strSql.Append("<td class='zt4'>" + dst.Tables[0].Rows[i]["SS_Name"].ToString() + "</td>");
                strSql.Append("<td class='zt4'>" + dst.Tables[0].Rows[i]["Phone1"].ToString() + "</td>");
                strSql.Append("<td class='zt4'>" + dst.Tables[0].Rows[i]["Phone2"].ToString() + "</td>");
                strSql.Append("<td class='zt4'>" + dst.Tables[0].Rows[i]["SS_Address"].ToString() + "</td></tr>");
            }
            strSql.Append("</table>");

            result = strSql.ToString();
        }
        catch (Exception ex)
        {
            Share.Alert(this.Page, ex.Message);
        }
    }

    public string GetCallbackResult()
    {
        return result;
    }
}
